////////////////////////////////////////////////////////////////////////////////
//(c) Intelliquip, Inc. 2001
////////////////////////////////////////////////////////////////////////////////
//$Log:
// 3    Version 10.0 (Current View)1.2         11/5/2010 1:05:26 PM   Stephen
//      Kish    IDD#6245: Refactoring changes
// 2    Version 10.0 (Current View)1.1         10/19/2010 2:26:25 PM  Stephen
//      Kish    IDD#6245: Refactoring HttpSessions.get and set Attribute to use
//      DAO classes
// 1    Version 10.0 (Current View)1.0         10/7/2010 4:47:46 PM   Jeff
//      Heigl      
//$
//$NoKeywords$
////////////////////////////////////////////////////////////////////////////////
package com.intelliquip.hydraulicselection.control.web;

import javax.servlet.http.HttpSession;

import com.intelliquip.constants.App;
import com.intelliquip.core.NewItemChoice;
import com.intelliquip.core.NewItemData;
import com.intelliquip.core.servlet.NewItemParams;
import com.intelliquip.core.servlet.NewItemServlet;
import com.intelliquip.hydraulicselection.UserPreferences;
import com.intelliquip.hydraulicselection.organization.OrgSetup;

public class NewItemServlet_Selector extends NewItemServlet {

	@Override
	protected void cacheUserSettings(HttpSession session) {
		try {
			SaveSettingsRedirectFilterSelector.cacheUserSettings(session);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	protected NewItemParams getNewItemParams(final HttpSession session) {
		final SessionAttributeDAO_Selector dao = new HttpSessionAttributeDAO_Selector(session);
		final UserPreferences userPreferences = dao.getUserPreferences();
		final NewItemData newItemData = userPreferences.getNewItemData();

		return new NewItemParams() {

			@Override
			public int getUserID() {
				return userPreferences.getUser().getID();
			}

			@Override
			public String getIfeLogoutAndTimeoutURL() {
				return dao.getIfeLogoutAndTimeoutURL();
			}

			@Override
			public String getOrgFolderHome() {
				return userPreferences.getOrgFolderHome();
			}

			@Override
			public NewItemData getNewItemData() {
				return newItemData;
			}

			@Override
			public String getDynamicID() {
				return userPreferences.getUser().getDynamicID();
			}

			@Override
			public NewItemChoice getDefaultNewItemChoice() {
				return newItemData.getFirstSelectorAppChoice();
			}

			@Override
			public boolean canRunQM() {
				return userPreferences.isQuoteManagerAccessPrivileged()
					&& "yes".equals(userPreferences.getOrgSetup().getValue(OrgSetup.QUOTEMGR_display));
			}

			@Override
			public String getAppName() {
				return App.SELECTOR.getAppName();
			}

			@Override
			public int getItemContainerID() {
				try {
					return userPreferences.getItemContainerIDOrDefaultID();
				} catch (Exception e) {
					e.printStackTrace();
					return -1;
				}
			}
		};
	}

}
